# SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
# SPDX-License-Identifier: Mulan PSL v2
FROM centos:7 as  builder

ENV WEBUI_DIR=/usr/local/webui-env

COPY CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo



# 安装git、sshpass、wget以及创建软件放置目录
RUN yum makecache && \

    # 安装git
    yum install git -y && \

    # 安装sshpass
    yum install sshpass -y && \

    # 安装wget
    yum -y install wget && \

    # 创建前端软件包的安装目录
    mkdir -p ${WEBUI_DIR}

# 安装node、yarn环境
RUN cd "$WEBUI_DIR" && \
    wget http://code.geniusai.org/UED/FE-COMMON/3parts/node-tar/raw/master/node-v14.18.1-linux-x64.tar.xz && \
    tar -xJ -f node-v14.18.1-linux-x64.tar.xz && \
    ln -s "$WEBUI_DIR"/node-v14.18.1-linux-x64/bin/node /usr/local/bin/ && \
    ln -s "$WEBUI_DIR"/node-v14.18.1-linux-x64/bin/npm /usr/local/bin/ && \
    ln -s "$WEBUI_DIR"/node-v14.18.1-linux-x64/bin/npx /usr/local/bin/ && \
    rm -f node-v14.18.1-linux-x64.tar.xz && \

    # 安装yarn
    npm install -g yarn --registry http://npm.uedc.geniusai.com.cn && \
    ln -s ${WEBUI_DIR}/node-v14.18.1-linux-x64/bin/yarn /usr/local/bin/ && \
    yarn config set registry http://npm.uedc.geniusai.com.cn/



# 安装 sfx2
ENV SFX_VERSION=v2.6.7
RUN cd ${WEBUI_DIR} && \
    wget http://code.geniusai.org/UED/FE-COMMON/sfx/-/archive/${SFX_VERSION}/sfx-${SFX_VERSION}.tar.gz && \
    tar -xf sfx-${SFX_VERSION}.tar.gz && \
    cd sfx-${SFX_VERSION} && \
    tar -xf ./lib/runtime/node_modules.tar node_modules && \
    rm -rf ./lib/runtime/node_modules.tar && \
    chmod +x ./bin/sfx2 && \
    ln -s ${WEBUI_DIR}/sfx-${SFX_VERSION}/bin/sfx2 /usr/bin/sfx2 && \
    cd ${WEBUI_DIR} && \
    rm -f sfx-${SFX_VERSION}.tar.gz


ADD . /root/ai

WORKDIR /root/ai


# 实际安装依赖和打包
RUN ls -lash && yarn install && sfx2 build && sfx2 build --config=theme.sfx.config.js


#From 10.211.3.23/system_containers/nginx:stable

From docker.geniusai.com/cicd_2740/build/nginx:stable

COPY nginx.conf /etc/nginx/nginx.conf

COPY default.conf /etc/nginx/conf.d/default.conf

COPY --from=builder /root/ai/dist  /usr/share/nginx/html/
